// components/singleWord/singleWord.js
const SpecialCharacter = ['.', '?', ':', ';', '!', ','];
Component({
    externalClasses: ['font-size'],
    properties: {
        renderTxt: {
            type: Array,
            value: []
        }
    },
    data: {
        MarkersTxT: '', //点击单词
        renderText: [],
        TageIndex:''//点击下标
    },
    observers: {
        renderTxt: function (arrdata) {
            const txt = [];
            for (let i = 0; i < arrdata.length; i++) {
                const tow = []
                arrdata[i].split(' ').forEach(item => {
                    // 获取最后一个符号
                    const segmentation = item.substring(item.length, item.length - 1)
                    if (SpecialCharacter.includes(segmentation)) {
                        const [A, B] = item.split(segmentation)
                        tow.push([A, B == "" ? segmentation : null])
                    } else {
                        tow.push(item)
                    }
                })
                txt.push(tow)
            }
         
            this.setData({
                renderText: txt
            })
        }
    },
    methods: {
        clickCi(e) {
            const MarkersTxT = e.currentTarget.dataset.danci;
            // 汉字和制定特殊字符不高亮
            if (/[\u4e00-\u9fa5]/.test(MarkersTxT) || SpecialCharacter.includes(MarkersTxT)) {
                return
            }
            this.triggerEvent('detailedWord',{MarkersTxT})

        //   setTimeout(() => {
            this.setData({
                MarkersTxT:this.data.MarkersTxT === MarkersTxT ? null : MarkersTxT,
                TageIndex:e.currentTarget.dataset.index
            })
        //   }, 100);

           
        }
    }
})